﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ZX.WebApp.WorkFlow
{
    public partial class Workformat : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    //实例化流程服务接口
                    CrmWorkFlowService.WorkFlowServiceClient workFlowServiceClient = new CrmWorkFlowService.WorkFlowServiceClient();
                    if (Request["logType"] != null && Request["WorkFlowInstanceId"] != null )
                    {
                        if (Request["WorkTaskInstanceId"] != null && Request["logType"].ToString() == "2")
                        {
                            string[] taskInstanceId = Request["WorkTaskInstanceId"].ToString().Split(',');
                            string[] flowInstanceId = Request["WorkFlowInstanceId"].ToString().Split(',');
                            for (int i = 0; i < flowInstanceId.Length; i++)
                            {
                                int status = workFlowServiceClient.GetWorkFlowErrorLogsColse(Request["logType"].ToString(), taskInstanceId[i], flowInstanceId[i]);
                            }
                            HttpContext.Current.Response.Write("1");
                        }
                        else if (Request["logType"].ToString() == "1")
                        {
                            bool status = workFlowServiceClient.UpdateWofkFlowInstance(Request["WorkFlowInstanceId"].ToString(), "1");
                            if (status)
                            {
                                HttpContext.Current.Response.Write("1");
                            }
                            else
                            {
                                HttpContext.Current.Response.Write("0");
                            }
                        }
                      
                    }
                    else
                    {
                        if (Request["WorkFlowInstanceId"] != null)
                        {
                            bool status = workFlowServiceClient.UpdateWofkFlowInstance(Request["WorkFlowInstanceId"].ToString(), "4");
                            if (status)
                            {
                                HttpContext.Current.Response.Write("1");
                            }
                            else
                            {
                                HttpContext.Current.Response.Write("0");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    HttpContext.Current.Response.Write("0");
                    throw ex;
                }
             
              
            }
        }
    }
}